package tiltmaze.view;

import java.util.ArrayList;
import tiltmaze.Maze;

/**
 * Class for storing and accessing past mazes by the means of Undo and Redo.
 * @author Juraj Niznan
 */
public class HistoryQueue {

    private ArrayList<Maze> queue = new ArrayList<Maze>();
    private int top = 0;
    private int current = 0;

    public void add(Maze m) {
        queue.add(current, m);
        current++;
        top = current;
    }

    public Maze undo() {
        if (current > 1) {
            current--;
            return queue.get(current - 1);
        } else {
            return null;
        }
    }

    public Maze redo() {
        if (top > current) {
            current++;
            return queue.get(current - 1);
        } else {
            return null;
        }
    }

    public Maze lastSaved() {
        if (top > 0) {
            return queue.get(top - 1);
        } else {
            return null;
        }
    }

    public boolean undoEnabled() {
        return (current > 1);
    }

    public boolean redoEnabled() {
        return (top > current);
    }
}
